### Project 28: Alarm Experiment ![](media/6db3cb7d3a91e700a3b651c1f0edb7a5.jpeg) **1. Overview** In the previous experiment, we control an output module though an input module. In this lesson, we will make an experiment that the active buzzer will emit sounds once an obstacle appears. **2. Components** ![image-20231020085302954](media/image-20231020085302954.png) **3. Connection Diagram** ![](media/e37efdec9676d47eaf8dabd2da41759a.png) **4. Test Code** ```Python from machine import Pin import time buzzer = Pin(4, Pin.OUT) sensor = Pin(15, Pin.IN) while True: buzzer.value(not(sensor.value())) time.sleep(0.01) ``` **5. Code Explanation** When an obstacle is detected, sensor.value() will return a low level signal. So when an obstacle is detected, the GPIO4 connected to the buzzer pin will output a high level signal, the buzzer will emit sounds. **6. Test Result** Connect the wires according to the experimental wiring diagram and power on. Click ![](media/da852227207616ccd9aff28f19e02690.png)“Run current script”, the code starts executing. The active buzzer will emit sound if detecting obstacles; otherwise, it won’t emit sound. Press “Ctrl+C”or click ![](media/27451c8a9c13e29d02bc0f5831cfaf1f.png)“Stop/Restart backend”to exit the program.